;;; packages - package definitions for GNU Guix
;;; Copyright (C) 2017 ng0
;;;
;;; This program is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Affero General Public License as
;;; published by the Free Software Foundation, either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU Affero General Public License for more details.
;;;
;;; You should have received a copy of the GNU Affero General Public License
;;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

(define-module (ng0 packages pen-web)
  #:use-module (guix build-system gnu)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix packages)
  #:use-module (gnu packages)
  #:use-module (gnu packages curl)
  #:use-module (gnu packages linux))

(define-public 0d1n
  (package
    (name "0d1n")
    (version "2.3")
    (source
     (origin
       (method url-fetch)
       (uri (string-append "https://github.com/CoolerVoid/0d1n/archive/"
                           version ".tar.gz"))
       (file-name (string-append name "-" version))
       (sha256
        (base32
         "1bjjvmzcm0n73mk4jdi5iwj5iqm5ly8faajha81yqqzyd016zqkz"))))
    (build-system gnu-build-system)
    (arguments
     `(#:tests? #f ; No tests
       #:phases
       (modify-phases %standard-phases
         (delete 'configure) ; No configure script
    (replace 'install
      (lambda* (#:key outputs #:allow-other-keys)
        ;; There is no structure.
        ;; TODO: Check if expectations like "/include" etc work.
        (let* ((out (assoc-ref outputs "out"))
               (bin (string-append out "/bin"))
               (share (string-append out "/share/0d1n")))
          (copy-recursively "doc" share)
          (copy-recursively "payloads" share)
          (copy-recursively "reponse2find" share)
          (copy-recursively "response_sources" share)
          (copy-recursively "tables" share)
          (install-file "0d1n" share)
          (mkdir-p bin)
          (symlink (string-append share "/0d1n")
                   (string-append bin "/0d1n"))
          (for-each (lambda (file)
                      (install-file file share))
                    (find-files "." "\\.h$"))
          (for-each (lambda (file)
                      (install-file file share))
                    (find-files "." "\\.conf$"))))))))
    (inputs
     `(("curl" ,curl)))
    (home-page "https://github.com/CoolerVoid/0d1n/")
    (synopsis "Web security tool to make fuzzing at HTTP")
    (description
     "0d1n is a tool for automating customized attacks against
web applications.  You can do:

@enumerate
@item brute force login and passwords in auth forms
@item directory disclosure (use PATH list to brute, and find HTTP status code)
@item test to find SQL Injection and XSS vulnerabilities
@item Options to load ANTI-CSRF token each request
@item Options to use random proxy per request
@item other functions...
@end enumerate\n")
    (license license:gpl3)))

(define-public blacknurse
  (let* ((commit "d2a2b23544295844714ebf8d2d78af37fe5770c9")
         (revision "1"))
    (package
      (name "blacknurse")
      (version (string-append "0.0.0-" revision "." (string-take commit 7)))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/jedisct1/blacknurse")
               (commit commit)))
         (file-name (string-append name "-" version))
         (sha256
          (base32
           "1w7zmcrnrs4p4naj3i6h1wcmd56dgrfd7myx0ljhw162sg0134nz"))))
      (build-system gnu-build-system)
      (arguments
       `(#:make-flags (list "CC=gcc")
         #:tests? #f ; No tests
         #:phases
         (modify-phases %standard-phases
           (delete 'configure) ; No configure script
           (replace 'install
             (lambda* (#:key outputs #:allow-other-keys)
               (let* ((out (assoc-ref outputs "out"))
                      (bin (string-append out "/bin")))
                 (install-file "blacknurse" bin)))))))
      (home-page "https://github.com/jedisct1/blacknurse")
      (synopsis "Proof of Concept for the Blacknurse attack")
      (description
       "Simple PoC for the Blacknurse (http://blacknurse.dk) attack.
Blacknurse is a low bandwidth ICMP attack that is capable of doing denial
of service to well known firewalls.")
      (license license:bsd-2))))

(define-public tsh-sctp
  (let* ((commit "850a2da4bfc13d691dafba60de4ca3c388f14544")
         (revision "1"))
    (package
      (name "tsh-sctp")
      (version (string-append "0.0.0-" revision "." (string-take commit 7)))
      (source
       (origin
         (method git-fetch)
         (uri (git-reference
               (url "https://github.com/infodox/tsh-sctp")
               (commit commit)))
         (file-name (string-append name "-" version))
         (sha256
          (base32
           "1f92y16ahyfr365z4dpv6qwf8ypailhdw4bwjx12vja6klxq2yi0"))))
      (build-system gnu-build-system)
      (inputs
       `(("lksctp-tools" ,lksctp-tools)))
      (arguments
       `(#:make-flags (list "linux")
         #:tests? #f ; No tests
         #:phases
         (modify-phases %standard-phases
           (delete 'configure) ; No configure script
           (replace 'build
             (lambda _
               (zero? (system* "make" "linux"))))
           (replace 'install
             (lambda* (#:key outputs #:allow-other-keys)
               (let* ((out (assoc-ref outputs "out"))
                      (bin (string-append out "/bin"))
                      (inc (string-append out "/include")))
                 (install-file "tsh" bin)
                 (install-file "tshd" bin)
                 (for-each (lambda (file)
                             (install-file file inc))
                           (find-files "." "\\.h$"))))))))
      (home-page "https://github.com/infodox/tsh-sctp")
      (synopsis "TinySHell port to SCTP")
      (description
       "Tiny SHell - An open-source UNIX backdoor")
      ;; It just says "GPL", which means any version of the
      ;; GPL unless specified.
      (license license:gpl3+))))

(define-public lksctp-tools
  (package
    (name "lksctp-tools")
      (version "1.0.17")
      (source
       (origin
         (method url-fetch)
         (uri (string-append "mirror://sourceforge/lksctp/lksctp-tools"
                             "/lksctp-tools-" version ".tar.gz"))
         (file-name (string-append name "-" version ".tar.gz"))
         (sha256
          (base32
           "05da6c2v3acc18ndvmkrag6x5lf914b7s0xkkr6wkvrbvd621sqs"))))
      (build-system gnu-build-system)
      (native-inputs
       `(("linux-libre-headers" ,linux-libre-headers)))
      (home-page "http://lksctp.sourceforge.net/")
      (synopsis "Linux Kernel Stream Control Transmission Protocol")
      (description
       "Stream Control Transmission Protocol (SCTP) is a reliable,
message-oriented, multihomed transport protocol.  Developed by the IETF
SIGTRAN working group to transport SS7 over IP, it is now the third
general-purpose transport developed by the IETF.")
      (license license:gpl2)))
